<template>
  <teleport :to="to">
    <div id="note-tip" :class="[to ? 'extend' : 'private']">
      <div class="target fs-12" :style="style">
        <div>{{ content }}</div>
      </div>
    </div>
  </teleport>
</template>

<script>
export default {
  name: "NTip",
};
</script>

<script setup>
import { onMounted } from "vue";
const props = defineProps({
  content: {
    type: String,
    default: "默认文本",
  },
  time: {
    type: Number,
    default: () => 1500,
  },
  close: Function,
  style: Object,
  to: {
    type: String,
    default: () => "body",
  },
});

const { time, content, to } = props;

onMounted(() => {
  setTimeout(() => {
    // 卸载提示弹窗
    props.close();
  }, time);
});
</script>

<style lang="less">
.extend {
  width: 100%;
  height: 100%;
}
.private {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
#note-tip {
  position: absolute;
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
  .target {
    position: absolute;
    width: 30%;
    min-height: 30px;
    color: white;
    line-height: 18px;
    padding: 10px 5px;
    text-indent: 1em;
    background-color: rgba(0, 0, 0);
    opacity: 0.7;
    border-radius: 10px;
    .close-icon {
      position: absolute;
      right: 1px;
      top: 2px;
      height: 14px;
      width: 14px;
      background: url("~@/assets/images/icon/close-white.png") no-repeat;
      background-size: contain;
    }
  }
}
</style>